<%@page import="javax.naming.spi.DirStateFactory.Result"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@page import="java.sql.ResultSet"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.SQLException" %>
<%
	request.setCharacterEncoding("utf-8");

    Connection conn =null;
	PreparedStatement pstmt = null; 
	ResultSet rs=null;
	
	String driver = "oracle.jdbc.driver.OracleDriver";
	String url = "jdbc:oracle:thin:@localhost:1521:orcl";
	String user = "scott";
	String password = "tiger";
	
	String seq=request.getParameter("seq");
	String passwd=request.getParameter("passwd");
	
	String subject = request.getParameter("subject");
	String writer =request.getParameter("writer");
	String mail =request.getParameter("mail");
	String content=request.getParameter("content");
	

	int flag=2; //기본 에러
	
	try{
		Class.forName(driver);
		conn=DriverManager.getConnection(url, user, password);
		String sql = "update board1 set subject=?, writer=?, mail=?, content=?  from board1 where seq=? and passwd=?";
		pstmt = conn.prepareStatement(sql);
		
		pstmt.setString(1, subject);
		pstmt.setString(2, writer);
		pstmt.setString(3, mail);
		pstmt.setString(4, content);
		pstmt.setString(5, seq);
		pstmt.setString(6, passwd);
	
		int result = pstmt.executeUpdate();
		
		if(result==1){
			flag=0;
		}else if(result==0){
			flag=1;
		}
		
	}catch(ClassNotFoundException e){
		System.out.println(e.getMessage());
	}catch(SQLException e){
		System.out.println(e.getMessage());
	}finally{
		if(pstmt!=null) pstmt.close();
		if(conn!=null) conn.close();
	}
	out.print("<script language='javascript'>");
	if(flag==0){
		out.print("alert('"+seq+"번 글이 수정 되었습니다.');");
		out.print("location.href='board_list1.jsp';");
	}else if(flag==1){
		out.print("alert('비밀 번호가 잘못 되었습니다.');");
		out.print("history.back();");
	}
	out.print("</script>");
	

%>